package com.aube.interact.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by huyaonan on 16/7/7.
 */
public class GoodsGroup implements Serializable {

    public List<GoodsItem> goodsVoList;

    public String lastId;

    public GoodsGroup() {
        goodsVoList = new ArrayList<>();
    }

    public void add(GoodsItem item) {
        goodsVoList.add(item);
    }

    public static GoodsGroup parse(JSONObject jsonObject) {
        GoodsGroup response = new GoodsGroup();
        try {
            JSONArray jsonArray = jsonObject.optJSONArray("goodsVoList");
            List<GoodsItem> goodsModels = new ArrayList<>();
            if(goodsModels != null) {
                for(int i=0; i<jsonArray.length(); i++)
                    goodsModels.add(GoodsItem.parse(jsonArray.optJSONObject(i)));
            }
            response.goodsVoList = goodsModels;
            response.lastId = jsonObject.optString("lastId");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }

}
